package com.dailyblue.java.cloud.provider.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.dailyblue.java.cloud.commons.util.JsonResult;
import com.dailyblue.java.cloud.commons.util.ResultTool;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/provider")
public class ProviderController {
    @Value("${server.port}")
    private Integer port;

    @SentinelResource(value = "pa")
    @GetMapping("/a")
    public JsonResult a() {
        log.info("用户访问了ProviderController`a方法！");
        return ResultTool.success("用户访问了ProviderController`a方法！port:" + port);
    }

    @GetMapping("/b")
    @SneakyThrows
    public JsonResult b() {
        log.info("用户访问了ProviderController`b方法！");
        Thread.sleep(2000);
        return ResultTool.success("用户访问了ProviderController`b方法！port:" + port);
    }

    @GetMapping("/c")
    public JsonResult c() {
        log.info("用户访问了ProviderController`c方法！");
        return ResultTool.success("用户访问了ProviderController`c方法！port:" + port);
    }

    @GetMapping("/d")
    public JsonResult d() {
        System.out.println(9 / 0);
        log.info("用户访问了ProviderController`d方法！");
        return ResultTool.success("用户访问了ProviderController`d方法！port:" + port);
    }
}
